﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using GameEngine.Scenes;
using GuiLibrary.layouts;

namespace GuiLibrary.Components
{
    public class SelectablePanel: Panel, ISelectableComponent
    {
        public Element elementAssociated { get; set; }
        public bool _isPointed;
        #region Constructors
        public SelectablePanel(Component parent, Vector2 relPosition, Background background, Layout layout, List<Component> components, Element elementAssociated) :
            base(parent, relPosition, background, layout, components) 
        {
            this.elementAssociated = elementAssociated;
        }
        public SelectablePanel(Component parent, Element elementAssociated) :
            this(parent,new Vector2(),null,null,new List<Component>(),elementAssociated) { }
        #endregion

        #region ISelectableComponent Members

        public Element getAssociatedElement()
        {
            return elementAssociated;
        }

        public bool isPointed()
        {
            return _isPointed;
        }

        public void onComponentPointed()
        {
            _isPointed = true;
            foreach (Component component in components) 
            {
                if (component is ISelectableComponent) 
                {
                    ISelectableComponent selComp = (ISelectableComponent)component;
                    selComp.onComponentPointed();
                }
            }
        }

        public void onComponentUnpointed()
        {
            _isPointed = false;
            foreach (Component component in components)
            {
                if (component is ISelectableComponent)
                {
                    ISelectableComponent selComp = (ISelectableComponent)component;
                    selComp.onComponentUnpointed();
                }
            }
        }

        #endregion
    }
}
